﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_PrintWholeKBRecord : System.Web.UI.Page
{
    int PWRProjectid;
    protected void Page_Load(object sender, EventArgs e)
    {
        string sql;
        string count = "";


        PWRProjectid = SysFun.ToInt(SysFun.IsSQL(MsgBox.JieMi_Decrypt(Request.QueryString["pid"])));
        Db db = new Db();
        System.Data.IDataReader dr;
        sql = "Select count(*) as cun From Show Where ShowProject=" + PWRProjectid.ToString() + " And ShowSort='1' ";//是否发布
        dr = db.DataReader(sql);
        while (dr.Read())
        {
            count = dr["cun"].ToString();
        }
        dr.Close();
        dr.Dispose();
        db.Close();
        if (count != "0")
        {
            showGridView();
        }
    }

    public void showGridView()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "kbgs" + PWRProjectid.ToString();
        dbPage.Key = "Bidid";
        dbPage.Where = strConditions;             
        //dbPage.SelectField = "ProductCode,ProductName,Outlookc,IsNull(Unit,'')+'/'+IsNull(PackUnit,'') As Pack1,Medicinemodel,goodsname,FactoryUserCode,factor,scname,smprice,spprice,QualityLevels,TBUserCode,TBRNAME";                             //可以不设，默认为“*”

        dbPage.SelectField = "GoodsId,ProductCode,ProductName,goodsname,Medicinemodel,Outlookc,factor,spprice,smprice, qualitylevels,SCNAME,FactoryUserCode,TBRNAME,TBUserCode ";
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 20;//Request.QueryString["PS"]);
        dbPage.OrderBy = "ProductName,Outlookc,Medicinemodel";
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        dr.Dispose();
        db.Close();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
    }

    public string fctConditions()
    {
        string ProductCode, ProductName, NameTB, UserCodeTB, NameSC, UserCodeSC;
        ProductCode=txtProductCode.Text;
        ProductName=txtProductName.Text;
        NameTB=txtNameTB.Text;
        UserCodeTB=txtUserCodeTB.Text;
        NameSC=txtNameSC.Text;
        UserCodeSC=txtUserCodeSC.Text;

        string strtemp = "";
        strtemp = " ProductCode is not null and";
        if (ProductCode != "") 
        {
            strtemp += " ProductCode like '%" + ProductCode + "%' And";
        }
        if (ProductName != "")
        {
            strtemp += " ProductName like '%" + ProductName + "%' And";
        }
        if (NameTB != "")
        {
            strtemp += " TBRNAME like '%" + NameTB + "%' And";
        }
        if (UserCodeTB != "")
        {
            strtemp += " TBUserCode like '%" + UserCodeTB + "%' And";
        }
        if (NameSC != "")
        {
            strtemp += " SCNAME like '%" + NameSC + "%' And";
        }
        if (UserCodeSC != "")
        {
            strtemp += " FactoryUserCode like '%" + UserCodeSC + "%' And";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;

    }

    protected void Button1_Click(object sender, EventArgs e)
    {

    }
}
